package br.edu.ufcg.dsc.actions.resource;

import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.ServletDispatcherResult;

import br.edu.ufcg.dsc.domain.Resource;
import br.edu.ufcg.dsc.domain.resource.ArticlesCollection;
import br.edu.ufcg.dsc.services.ResourceService;

import com.opensymphony.xwork2.Preparable;

@Result(name = "success", type = ServletDispatcherResult.class, value = "/jsp/resource/articlesCollection.jsp")
public class FindArticlesCollectionAction extends ResourceDriven<ArticlesCollection> implements Preparable{
	
	private int resourceId;
	private ArticlesCollection articleCollection;
	
	private static final long serialVersionUID = 1L;

	public void prepare() throws Exception {
		Resource resource = ResourceService.find(resourceId);
		if (resource != null)
			articleCollection = new ArticlesCollection(resource.getMarc());
		else articleCollection = new ArticlesCollection();
	}

	public int getResourceId() {
		return resourceId;
	}

	public void setResourceId(int resourceId) {
		this.resourceId = resourceId;
	}

	public ArticlesCollection getArticleCollection() {
		return articleCollection;
	}

	public void setArticleCollection(ArticlesCollection articleCollection) {
		this.articleCollection = articleCollection;
	}

	public ArticlesCollection createModel() {
		return articleCollection;
	}

	public String execute(){		
		return SUCCESS;
	}

}
